define(["require", 'config/appregister', 'business/postbar/service/postbarhttp', "jquery", "business/services/filter"], function(require, app, httpServices) {
    app.controller('searchQuestionCtrl', function($scope, $http, $state, $stateParams) {
        $scope.$parent.isDetailPage = false;
        $scope.$parent.isMainpage = true;
        $scope.listParams = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize: 10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName: "",
            scName: ""
        };
	  	if(sessionStorage.hasOwnProperty("searchKeyWord")){
    		$scope.listParams.keyWord = sessionStorage.searchKeyWord;
        };

        function getListModel() {
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage: $scope.listParams.pageSize,
                //分页总数
                numberOfPages: Math.ceil($scope.totalItem / $scope.listParams.pageSize),
                // 实际分页长度
                pagesLength: 5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function(currentPage) {
                    if(currentPage) {
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getList();
                }
            };
        };

        $scope.gotoiask = function() {
            $state.go("eng.iask");
        };



        $scope.change = function($index) {
            var thenum = $index;
            if(thenum % 2 == 0) {
                return {
                    "background-color": "#fff"
                }
            } else {
                return {
                    "background-color": "#f5f5f5"
                };
            };
        };
        //
        var pdd = 0;
        $scope.showli1 = function() {
            pdd++;
            if(pdd == 1) {
                $('.pa1').css("display", "block");
            } else {
                pdd = 0;
                $('.pa1').css("display", "none");
            };
        };

        $scope.showli2 = function() {
            pdd++;
            if(pdd == 1) {
                $('.pa2').css("display", "block");
            } else {
                pdd = 0;
                $('.pa2').css("display", "none");
            };
        };
        $scope.showli3 = function() {
            pdd++;
            if(pdd == 1) {
                $('.pa3').css("display", "block");
            } else {
                pdd = 0;
                $('.pa3').css("display", "none");
            };
        };
		//鼠标点击后排序样式
		var actj = true;
		$scope.activesj = function() {
			if(actj) {
				actj = false;
				time = true;
				$("#sj").css({
					"background":"url("+'them/img/sjdown.png'+") 28px 2px no-repeat",
					"background-size":"10px 10px",
					"color":"#30a3ff"
				});
				getList();				
			}else {
				actj = true;
				time = false;
				$("#sj").css({
					"background":"url("+'them/img/rqup.png'+") 28px 2px no-repeat",
					"background-size":"10px 10px",
					"color":"#000"
				});
				getList();				
			}
		};
		
		var actq = true;
		$scope.activerq = function() {
			if(actq){
				actq = false;
				replyCount = true;
				$("#rq").css({
					"background":"url("+'them/img/sjdown.png'+") 49px 2px no-repeat",
					"background-size":"10px 10px",
					"color":"#30a3ff"			
				});
				getList();				
			}else {
				actq = true;
				replyCount = false;
				$("#rq").css({
					"background":"url("+'them/img/rqup.png'+") 49px 2px no-repeat",
					"background-size":"10px 10px",
					"color":"#000"			
				});
				getList();				
			}
		};
		//点击相关搜索词变色
		$scope.clickcolor = function() {
			$(".datadiv").change(function(){
				$(this).css("color","#30a3ff");
			});
		};
		//获取问题/排行
		getquestion()
		function getquestion() {
			var req = {
				type:'GET',
				uri:'getPostbarRank',
				data:{
					count:8
				}
			};
			httpServices.postbarlistHttpService(req).success(function(data){
				if(!data)return;
				if(data.code == 0) {
					$scope.$apply(function() {
						$scope.otherdata = data.data;
						$scope.gotoxq = function(the) {
							$state.go("eng.postbardeta",{postbarId:the});
						};
					});
				} else {
					console.log(data.msg);
				}			
			}).error(function(){
				console.log("获取相关问题请求失败");
			});
		};
		//我要提问跳转
		$scope.gotopage = function() {
			$state.go("eng.iask");
		}
		
		
		$scope.getStyle  =function(oo,tt){
			if(oo==0){
				return {
					border:"1px solid #ec251f",
					color:"#ec251f"
				};
			}else if(oo>0&&tt==1){
				return {
					border:"1px solid #35b558",
					color:"#35b558"
				};
			}else if(oo>0&&tt==2){
				return {
					border:"1px solid #ccc",
					color:"#ccc"
				};				
			}	
		};
        //
        $scope.jump = function(a) {
            $state.go("eng.postbardeta",{postbarId:a});
        };
        //
        $scope.returnCSS = function(the) {
            if(the == 2) {
                return {
                    "background": "url('them/img/yespic.png') 6px 10px no-repeat",
                    "background-size": "50px 24px"
                }
            } else {
                return {
                    "opacity": "0"
                }
            }
        };
        //右边list
        var pages = 1,
            pagesize = 10,
            all = false,
            boon = false;
		
		var time = false;
		var replyCount = false;
        function getList() {
        	if(!$scope.listParams.keyWord){
        		$scope.listParams.keyWord = null;
        	}
            momo = 0;
            var req = {
                type:'GET',
                uri:'getListByKeyWord',
                data:{
                    time:time,
                    replyCount:replyCount,
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize,
                    keyWord:$scope.listParams.keyWord,
                    all:all
                    
                }
            };
            httpServices.postbarlistHttpService(req).success(function(data){
                if(!data)return;
                	$scope.$apply(function() {
                		 if(data.code==0) {
	                    	$scope.allnum = data.data.Pagination.totalCount;
	                        $scope.qqq = data.data.list;
	                        $scope.totalItem = data.data.Pagination.totalCount;
	                        $scope.listParams.pageNo = data.data.Pagination.pageNo;
	                        $scope.listParams.pageSize = data.data.Pagination.pageSize;
	                        getListModel();
               			}else {
                    		console.log(data);
            		    };
                    });
            }).error(function(){
                console.log("百问百达列表请求失败！")
            });
        };
        getList();
        //右边盒子头部选项卡

        //1级分类
        var req = {
            type:'GET',
            uri:'getTopCategory'
        };
        httpServices.oneclassHttpService(req).success(function(data){
            if(data.code==0){
                $scope.$apply(function() {
                    $scope.aaa = data.data;
                })
            }else{
                console.log(data.msg);
            }
        }).error(function(){
            console.log("一级分类请求失败");
        });

        $scope.isShow = [];
        var gay = 0;

        $scope.isShows = [];
        var lala = 0;
        $scope.isShowInter = false;
        $scope.isShowOther = !$scope.isShowInter;
    })
})